var wroker=new Worker("./worker.js")

var channel=new MessageChannel()

// console.log(channel);

channel.port1.onmessage=(event)=>{
    console.log('子进程消息',event.data);
    const ele=document.querySelector("#result")
    ele.innerHTML=event.data
}

function sendMsg(){
    const ele=document.getElementById("msg")
    msg=ele.value
    // console.log(msg);
    /**
     * main.js:17 Uncaught DataCloneError: Failed to execute 'postMessage' on 'Worker': Port at index 0 is already neutered.
     *当我们使用 postMessage 方法传递 MessageChannel 的端口时，传递的端口（port2）实际上被“转移”到了 Worker 线程。这个端口在转移后就不能再在主线程使用，否则就会产生 DataCloneError。 
    */
    wroker.postMessage({
        port1:channel.port2,
        message:msg
    },[channel.port2])
    ele.value=""
}
